package com.jd.finance.core.controller.admin;


import com.jd.finance.core.service.ContractService;
import com.jd.finance.core.service.impl.AdminUtilsServiceImpl;
import com.jd.finance.result.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 劳动合同表 前端控制器
 * </p>
 *
 * @author LiQingBo
 * @since 2022-05-25
 */
@Api(tags = "合同管理")
@Slf4j
@RestController
@RequestMapping("/admin/core/adminContractCenter")
public class AdminContractController {

    @Resource
    private AdminUtilsServiceImpl adminUtilsService;

    @Resource
    private ContractService contractService;

    @ApiOperation("添加后台用户劳务合同")
    @PostMapping("/addContract")
    public BaseResult addContract(Integer hrId,Integer uid,String contBegTime,String contFinishTime,HttpServletRequest request) {

        if (StringUtils.isAllBlank(String.valueOf(hrId),String.valueOf(uid),contBegTime,contFinishTime)) {
            log.error("添加合同，提交信息为空!");
            return BaseResult.error().message("添加合同，提交信息为空!");
        }

        if (!adminUtilsService.isHR(hrId)) {
            log.error("该用户非HR身份!");
            return BaseResult.error().message("该用户非HR身份!");
        }

        return contractService.addContract(hrId,uid,contBegTime,contFinishTime,request);
    }
}

